package tardistv.model;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author TV Tardis Team
 */
public class EpisodeTableModel extends AbstractTableModel {

    private String[] columnNames = {"Name", "Number", "Aired", "Torrent"};
    private Object[][] data;


    public void showNewShow(Show show) {
        ArrayList<Episode> episodes = show.getEpisodes();
        data = new Object[episodes.size()][4];
        for (int i = 0; i < data.length; i++) {
            Episode episode = episodes.get(i);
            data[i][0] = episode.getName();
            data[i][1] = episode.getNumber();
            data[i][2] = episode.isAired();
            data[i][3] = episode.getTorrent();
        }
        fireTableDataChanged();
    }

    @Override
    public String getColumnName(int col) {
        return columnNames[col];
    }

    @Override
    public int getRowCount() {
        if (data == null) {
            return 0;
        }
        return data.length;
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return data[rowIndex][columnIndex];
    }
}
